This list will be simply used as a list of arguments for a function accepting all the variables defined in the HTML form as keys. Hence, we rely on the standard Lisp binding mechanism to bind each value to its variable. For our purpose, we ask the appropriate dictionary for an HTML version of the entry structure.
Listing 3:
wAlex.acgi 2/3 (MCL Application)
Getting the corresponding entry
(defun get-walex-entry (&key dictid
dicttype
formname
entry
&allow-other-keys)
;; Now, we can directly use each variable to query our dictionary
(let ((dict (get-dictionary dictid dicttype)))
(findAndTransmuteItem
dict
entry :output-format :html-1))
)
Replying
MacHTTP expects the Apple event reply’s direct parameter to contain an HTTP/1.0 header and HTML text that will be transmitted to the client. Hence, we have to construct an appropriate answer. The HTML/1.0 header will be built as a global variable:
;; Define the http 1.0 header (beware of crlf)
(defvar *crlf*
(format nil "~A~A" #\Linefeed #\Newline))
(defvar *http-10-header*
(format nil "HTTP/1.0 200 OK ~A~
Server: MacHTTP ~A~
MIME-Version: 1.0 ~A~
Content-type: text/html ~A~A"
*crlf* *crlf* *crlf* *crlf* *crlf*))
The reply itself will be returned by the findAndTransmuteItem function. Hence, we just have to put the header and answer in the Apple event reply’s direct parameter with the ae-put-parameter-char function.
Listing 4:
wAlex.acgi 3/3 (MCL Application)
Defining and installing the Apple event handler
(defmethod my-ae-handler ((a application)
theAppleEvent
reply
handlerRefcon)
;; We don’t use the handlerRefcon argument
(declare (ignore handlerRefcon))
;; Just get the post parameter, decode it, handle it and reply
(let* ((post-args
(create-keywords-from-args
(ae-get-parameter-char theAppleEvent
:|post| t)))
(the-answer
(apply #'get-walex-entry post-args)))
;; Build the reply and put it into the Apple event reply’s direct parameter
-- Open a base from a given filename. Return an index dictionary or 0 in case of error.
on openAlexDictionary(filename)
tell theApp
return do script ¬
("(alex::open-object :alex-base :return-index t :file
(pathname \"" & filename & "\"))")
end tell
end openAlexDictionary
getAlexDictionaryName
-- Return the dictionary name based on the dictionary id.
on getAlexDictionaryName(id)
tell theApp
return do script ("(alex:name (alex::base
(alex::get-dict-handler \"" & id & "\" :id)))")
end tell
end getAlexDictionaryName
deleteAlexEntryWithID
-- Deletes an entry (if defined) based on the dictionary id.
on deleteAlexEntryWithID(id, entry)
tell theApp
do script ("(delete-item (alex::base
(alex::get-dict-handler \"" & id & "\" :id)) :key "
& "\"" & entry & "\"" & ")")
end tell
end deleteAlexEntryWithID
Listing 8:
Two CLOS Headers for Plain Text and HTML Formatting
transmute-entry
First method for of text output (code not detailed).
(defmethod transmute-entry (entry
(entry-type (eql :en-entry))
(output-format (eql :text)) )
…)
Second method for one kind of HTML output (code not detailed).
(defmethod transmute-entry (entry
(entry-type (eql :en-entry))
(output-format (eql :html-1)) )
…)
Listing 9:
High-level Format of ALEX Items
High-level format for “apple”
The high level format of ALEX is a (kind of) property list. The first item is always the type of the entry. The rest of the structure is made of an open list composed of a type and one or several string values.
(:EM-ENTRY (:ENTRY "apple") (:C "n") (:N "1") (:G "(tree)") (:ME "pokok epal") (:N "2") (:G "(fruit)") (:ME "(buah) epal") (:P "an apple") (:P "the apple") (:P "bad apple") (:P "rotten apple") (:MPE "orang yg tdk baik") (:P "an apple for the teacher") (:MPE "sogokan") (:MPE "tumbuk rusuk") (:P "an apple of discord") (:P "the apple of discord") (:MPE "punca perselisihan") (:MPE "punca pergaduhan") (:MPE "punca perkelahian") (:P "the apple of o's eye") (:MPE "kesayangan sso") (:MPE "buah hati."))
Requested output format
The code produced by ALEX for the entry “apple” is given in listing 10 (the code has been slightly edited for readability). Besides the cosmetic features of the page, the most interesting part of the listing is the handling of the “previous” and “next” entries.
Listing 10:
Source of Figure 2
HTML “apple”
Beginning of the header of the page and control part for access to the previous and next entries.
<B>1</B> - (tree); <IMG SRC="http://161.142.8.195/wSambre-us/ALEX/Gifs/cyan-diamond.GIF"> pokok epal <IMG HSPACE=6 SRC="http://161.142.8.195/wSambre-us/ALEX/Gifs/red-diamond.GIF">
<B>2</B> - (fruit); <IMG SRC="http://161.142.8.195/wSambre-us/ALEX/Gifs/cyan-diamond.GIF"> (buah) epal rotten apple, bad apple, the apple, an apple; <IMG SRC="http://161.142.8.195/wSambre-us/ALEX/Gifs/cyan-diamond.GIF"> orang yg tdk baik an apple for the teacher; <IMG SRC="http://161.142.8.195/wSambre-us/ALEX/Gifs/cyan-diamond.GIF"> tumbuk rusuk, sogokan the apple of discord, an apple of discord; <IMG SRC="http://161.142.8.195/wSambre-us/ALEX/Gifs/cyan-diamond.GIF"> punca perkelahian, punca pergaduhan, punca perselisihan the apple of o's eye; <IMG SRC="http://161.142.8.195/wSambre-us/ALEX/Gifs/cyan-diamond.GIF"> buah hati., kesayangan sso.</DL>
Information to remind the user in which dictionary he is looking.